home *** CD-ROM | disk | FTP | other *** search
- /*
- File: UnitTablePCExchangeSupport.c
-
- Contains: All functionality needed especially for PC Exchange/FSM support.
-
- Version: 1.0
-
- Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
- */
-
- #include "UnitTablePCExchangeSupport.h"
- #include "UnitTableDriveQSupport.h"
-
- // The parameters userData and callBack are currently unused because all requests will complete
- // immediately. If at a later point a request is added that needs to call the DAM, an internal
- // paramter block will need to be created, and these values saved.
- OSStatus PCExchangeControlCallSupport( UInt32 userData,
- CntrlParamPtr cntrlPBPtr,
- ControlStatusCompletionProcPtr callBack )
- {
- #pragma unused ( userData, callBack )
-
- OSStatus err = noErr;
- SInt16 driveNum;
-
- driveNum = cntrlPBPtr->ioVRefNum;
-
- // Parse the control codes…
- switch( cntrlPBPtr->csCode )
- {
- case kRegisterPartition: // Register New Partition
- {
- // PCX will call this function when it wants to redefine a partition. It will
- // pass in the drive queue element pointer of the partition to redefine, the
- // new starting physical block offset, and the new block length.
- if( AreThereMountedDrives() == false )
- {
- err = nsDrvErr; // no Media is inserted, return an error
- }
- else
- {
- DrvQElPtr theDrvQEl; // drive queue element pointer
- UInt32 *altParams; // local pointer to alternate control parameters
-
- altParams = (UInt32 *) (&cntrlPBPtr->csParam[0]); // alternate parameters
- theDrvQEl = (DrvQElPtr) altParams[THE_DRIVE];
- if ( theDrvQEl != nil ) // if valid queue element pointer
- {
- DriveQRecPtr vol = nil; // pointer to our volume record structure
-
- vol = FindDriveQRecForDriveNum( theDrvQEl->dQDrive );
- if ( vol ) // and valid volume reference
- {
- vol->partoffset = altParams[THE_PHYS_START]; // new partition offset
- vol->curoffset = vol->partoffset; // current offset changes also
- vol->partblks = altParams[THE_PHYS_SIZE]; // new partition size
-
- UpdateQ(theDrvQEl->dQDrive, vol->partblks); // Update drive queue capacity
- vol->diskInsertPosted = true; // PCX will handle the Disk Insert event
- err = noErr; // clear error
- }
- else
- {
- err = nsDrvErr; // no Media is inserted, return an error
- }
- }
- else
- {
- err = nsDrvErr; // invalid DriveQEl was passed in
- }
- }
- }
- break;
-
- case kGetADrive: // Get A Drive (Create New Partition)
- {
- // PCX calls this function to add a new partition. The new partition's DrvQElPtr is
- // returned. NOTE: If the driver handles multiple drives note that PCX does not pass
- // in the physical drive number on which to create the new partition. However, the
- // DrvQElPtr stored at the pointer passed in is for another partition on the drive.
- if( AreThereMountedDrives() == false )
- {
- err = nsDrvErr; // no Media is inserted, return an error
- }
- else
- {
- // PC Exchange does not pass in a drive number, because the purpose of this
- // control call is to allow PC Exchange to create new drives for a disk
- // that has multiple DOS partitions
- UInt32 *altParams; // local pointer to alternate control parameters
-
- altParams = (UInt32 *) (&cntrlPBPtr->csParam[0]); // alternate parameters
- if (altParams[THE_VAR_QUEL] == nil) // verify a valid queue element handle
- {
- err = paramErr;
- }
- else
- {
- // create a new volume record and DrvQEl associated with the physical drive.
- // The new volume starts at offset 0 and has no capacity yet. By default, the
- // partition will not have a partition map entry on the media.
- DriveQRecPtr vol = nil; // pointer to our volume record structure
-
- vol = CreateNewDriveQRecForPartition( NextPartitionID(), 0, 0 );
- if ( vol )
- {
- // Return the DrvQElPtr at the location passed in…
- *((DrvQElPtr*)altParams[THE_VAR_QUEL]) = (DrvQElPtr) &vol->driveStatus.qLink;
- err = noErr;
- }
- else
- {
- err = controlErr;
- }
- }
- }
- }
- break;
-
- case kProhibitMounting:
- {
- // This PC Exchange control call is currently not supported,
- // need to verify that this is still used.
- err = controlErr;
- }
- break;
-
- default:
- {
- err = controlErr;
- }
- break;
- }
-
- return err;
- }
-
- // The parameters userData and callBack are currently unused because all requests will complete
- // immediately. If at a later point a request is added that needs to call the DAM, an internal
- // paramter block will need to be created, and these values saved.
- OSStatus PCExchangeStatusCallSupport( UInt32 userData,
- CntrlParamPtr cntrlPBPtr,
- ControlStatusCompletionProcPtr callBack )
- {
- #pragma unused ( userData, callBack )
- OSStatus err = noErr;
- SInt16 driveNum;
-
- driveNum = cntrlPBPtr->ioVRefNum;
-
- // Parse the status codes…
- switch(cntrlPBPtr->csCode)
- {
- case kGetPartitionStatus:
- {
- // I have never seen this called, who uses it?
- UInt32 *altParams; // alternate csParams as long words
- partInfoRecPtr thePartInfo;
-
- altParams = (UInt32 *) &cntrlPBPtr->csParam[0]; // alternate parameters
- thePartInfo = (partInfoRecPtr) altParams[kDeviceToQuery];
- if( thePartInfo != nil )
- {
- DriveQRecPtr vol = nil;
-
- vol = FindDriveQRecForPartitionNum( thePartInfo->partitionNumber );
- if ( vol != nil )
- {
- altParams[kDeviceResponse] = vol->driveNum;
- err = noErr;
- }
- else
- {
- err = nsDrvErr; // no Media is inserted, or this is not our drive, return an error
- }
- }
- else
- {
- err = nsDrvErr; // no Media is inserted, or this is not our drive, return an error
- }
- }
- break;
-
- case kGetPartInfo:
- {
- // PCX will call this function to get info on the specified partition.
- // Return the physical drive reference, the starting block offset, and
- // the partition ID (any relative non-zero reference).
- if( AreThereMountedDrives() == false )
- {
- err = nsDrvErr; // no Media is inserted, return an error
- }
- else
- {
- DriveQRecPtr vol = nil;
-
- vol = FindDriveQRecForDriveNum( driveNum );
- if( vol != nil )
- {
- UInt32 *altParams; // alternate csParams as long words
- partInfoRecPtr thePartInfo;
-
- altParams = (UInt32 *) &cntrlPBPtr->csParam[0]; // alternate parameters
- thePartInfo = (partInfoRecPtr) altParams[kPartInfoResponse];
-
- // SCSIID is not defined for non-SCSI devices. Return zero
- *((UInt32 *)&thePartInfo->SCSIID) = 0;
-
- thePartInfo->physPartitionLoc = vol->partoffset;
- thePartInfo->partitionNumber = vol->partitionNo;
- err = noErr;
- }
- else
- {
- err = nsDrvErr; // no Media is inserted, or this is not our drive, return an error
- }
- }
- }
- break;
-
- default:
- {
- err = statusErr;
- }
- break;
- }
-
- return err;
- }
-
-